package com.ruoyi.business.service.impl;

import com.ruoyi.business.mapper.WsdGradesMapper;
import com.ruoyi.business.service.IWsdGradesService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.entity.WsdClasses;
import com.ruoyi.common.core.domain.entity.WsdGrades;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/**
 * 年级信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-14
 */
@Service
public class WsdGradesServiceImpl implements IWsdGradesService
{
    @Autowired
    private WsdGradesMapper wsdGradesMapper;

    @Autowired
    private WsdClassesServiceImpl wsdClassesService;

    /**
     * 查询年级信息
     *
     * @param id 年级信息主键
     * @return 年级信息
     */
    @Override
    public WsdGrades selectWsdGradesById(Long id)
    {
        return wsdGradesMapper.selectWsdGradesById(id);
    }

    /**
     * 查询年级信息列表
     *
     * @param wsdGrades 年级信息
     * @return 年级信息
     */
    @Override
    public List<WsdGrades> selectWsdGradesList(WsdGrades wsdGrades)
    {
        List<WsdGrades> wsdGradesList = wsdGradesMapper.selectWsdGradesList(wsdGrades);
        for (WsdGrades wsdGrades1 : wsdGradesList) {
            String className = "";
            WsdClasses wsdClasses1 = new WsdClasses();
            wsdClasses1.setGradeId( wsdGrades1.getId() );
            List<WsdClasses> wsdClasses = wsdClassesService.selectWsdClassesList(wsdClasses1);
            for (WsdClasses wsdClassesList : wsdClasses){
                className += wsdClassesList.getName()+",";
            }
            wsdGrades1.setClassNames(className);
        }
        return wsdGradesList;
    }

    /**
     * 新增年级信息
     *
     * @param wsdGrades 年级信息
     * @return 结果
     */
    @Override
    public int insertWsdGrades(WsdGrades wsdGrades)
    {
        SysUser user = getLoginUser().getUser();
        Long schoolId = user.getSchoolId();
        wsdGrades.setSchoolId(schoolId);
        wsdGrades.setCreateTime(DateUtils.getNowDate());
        return wsdGradesMapper.insertWsdGrades(wsdGrades);
    }

    /**
     * 修改年级信息
     *
     * @param wsdGrades 年级信息
     * @return 结果
     */
    @Override
    public int updateWsdGrades(WsdGrades wsdGrades)
    {
        wsdGrades.setUpdateTime(DateUtils.getNowDate());
        return wsdGradesMapper.updateWsdGrades(wsdGrades);
    }

    /**
     * 批量删除年级信息
     *
     * @param ids 需要删除的年级信息主键
     * @return 结果
     */
    @Override
    public int deleteWsdGradesByIds(Long[] ids)
    {
        return wsdGradesMapper.deleteWsdGradesByIds(ids);
    }

    /**
     * 删除年级信息详细
     *
     * @param id 年级信息主键
     * @return 结果
     */
    @Override
    public int deleteWsdGradesById(Long id)
    {
        return wsdGradesMapper.deleteWsdGradesById(id);
    }
}
